<%@ page contentType="text/html;charset=UTF-8" language="java" %> <%@ page isELIgnored="false" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt" %>
<%
  String path = request.getContextPath();
  String basePath = request.getScheme() + "://" + request.getServerName() + ":" + request.getServerPort() + path + "/";
  String _id=request.getParameter("_");
  String jsessionid = session.getId();
%>

        <div class="panel">
            <div class="panel-heading header">
                <h3 class="panel-title" id="title">发文申请表</h3>
            </div>

            <!-- BASIC FORM ELEMENTS -->
            <!--===================================================-->
            <form id="form_dispatch_input" class="form-horizontal">

                <input type="hidden" name="keyId" id="keyId" value="${dispatch.id}"/>
                <input type="hidden" name="curDutyId" id="curDutyId" value=""/>

                <div class="form-group">
                    <label class="col-md-2 control-label"> 发文类别<i class="fa fa-asterisk txt-color-red"></i></label>
                    <div class="col-md-6">
                        <select name="typedictId" id="typedictId" class="form-control">
                            <option></option>
                            <c:forEach var="item" items="${typeDict}" varStatus="status">
                             <option value="${item.id}" <c:if test="${item.id == dispatch.type.id}"> selected="selected"</c:if>>${item.name}</option>
                            </c:forEach>
                        </select>
                    </div>
                </div>

                <div class="form-group">
                    <label class="col-md-2 control-label">发文标题<i class="fa fa-asterisk txt-color-red"></i></label>
                    <div class="col-md-6">
                        <input type="text" name="title" id="title1" class="form-control" placeholder="请输入发文标题" value="${dispatch.title}">
                    </div>
                </div>

                <div class="form-group">
                    <label class="col-md-2 control-label">文件编号<i class="fa fa-asterisk txt-color-red"></i></label>
                    <div class="col-md-6">
                        <input type="text"  name="fileNo" id="fileNo"  class="form-control" placeholder="请输入文件编号" value="${dispatch.fileNo}">
                    </div>
                </div>

                <div class="form-group">
                    <label class="col-md-2 control-label">
                        发文时间<i class="fa fa-asterisk txt-color-red"></i>
                    </label>
                    <div class="col-md-6">
                        <input  placeholder="请选择发文时间"  id="time" name="time" class="form-control"
                                type="text" value="<fmt:formatDate pattern="yyyy-MM-dd" value="${dispatch.time}" />">
                    </div>
                </div>

                <div class="form-group">
                    <label class="col-md-2 control-label">
                        发文对象<i class="fa fa-asterisk txt-color-red"></i>
                    </label>
                    <div class="col-md-6">
                        <div class="radio">
                            <input type="radio" name="object" id="object1" value="1" class="magic-radio" <c:if test='${dispatch == null || dispatch.object == null || dispatch.object=="1"}'> checked</c:if> >
                            <label for="object1">全体员工</label>
                            <input type="radio" name="object" id="object2" value="2" class="magic-radio" <c:if test='${dispatch.object=="2"}'>checked</c:if> >
                            <label for="object2">部门</label>
                            <input type="radio" name="object" id="object3" value="3" class="magic-radio" <c:if test='${dispatch.object=="3"}'>checked</c:if> >
                            <label for="object3">个人</label>
                        </div>
                    </div>
                </div>

                <div class="form-group">
                    <label class="col-md-2 control-label">
                        是否具有有效期<i class="fa fa-asterisk txt-color-red"></i>
                    </label>
                    <div class="col-md-6">
                        <div class="radio">
                            <input type="radio" name="hasValid" id="hasValidYes" value="1" class="magic-radio" <c:if test="${dispatch.hasValid==true}"> checked</c:if> >
                            <label for="hasValidYes">是</label>
                            <input type="radio" name="hasValid" id="hasValidNo" class="magic-radio" value="0" <c:if test="${dispatch.hasValid==false}"> checked</c:if> >
                            <label for="hasValidNo">否</label>
                        </div>
                    </div>
                </div>

                <div class="form-group" <c:if test="${dispatch==null || dispatch.hasValid!=true}">style="display:none"</c:if> id="showValid">
                    <label class="col-md-2 control-label">
                        有效期<i class="fa fa-asterisk txt-color-red"></i>
                    </label>
                    <div class="col-md-6">
                        <input  placeholder="请选择有效期" id="validDate" name="validDate" class="form-control"
                                type="text" value="<fmt:formatDate pattern="yyyy-MM-dd" value="${dispatch.validDate}" />">
                    </div>
                </div>

                <div class="form-group" <c:if test='${dispatch == null || dispatch.object!="2"}'>style="display:none"</c:if> id="showDept">
                    <label class="col-md-2 control-label">
                        <a href="javascript:void(0);" onclick="fn_departments_dialog_select('y','noticeDepartment','noticeDepartmentId')" style="color: #4FA5D0">通知部门</a>
                        <i class="fa fa-asterisk txt-color-red"></i>
                    </label>
                    <div class="col-md-6">
                        <input type="text" id="noticeDepartment" name="noticeDepartment" class="form-control" placeholder="请选择通知部门" disabled
                               value="<c:forEach var="item" items="${dispatch.noticeDepartment}" varStatus="status">${item.name}<c:if test="${!status.last}">,</c:if></c:forEach>">
                        <input type="hidden" id="noticeDepartmentId" name="noticeDepartmentId"
                               value="<c:forEach var="item" items="${dispatch.noticeDepartment}" varStatus="status">${item.id}<c:if test="${!status.last}">,</c:if></c:forEach>">
                    </div>
                </div>

                <div class="form-group" <c:if test='${dispatch== null || dispatch.object!="3"}'>style="display:none"</c:if> id="showPerson">
                    <label class="col-md-2 control-label">
                        <a href="javascript:void(0);" onclick="fn_members_dialog_select('noticeUser', 'noticeUserId')" style="color: #4FA5D0">通知个人</a>
                        <i class="fa fa-asterisk txt-color-red"></i>
                    </label>
                    <div class="col-md-6">
                        <input type="text" id="noticeUser" name="noticeUser" class="form-control" placeholder="请选择通知个人" disabled
                               value="<c:forEach var="item" items="${dispatch.noticeUsers}" varStatus="status">${item.name}<c:if test="${!status.last}">,</c:if></c:forEach>">
                        <input type="hidden" id="noticeUserId" name="noticeUserId"
                               value="<c:forEach var="item" items="${dispatch.noticeUsers}" varStatus="status">${item.id}<c:if test="${!status.last}">,</c:if></c:forEach>">
                    </div>
                </div>

                <div class="form-group">
                    <label class="col-md-2 control-label">  相关附件</label>
                    <div class="col-md-6">
                        <input name="uploadify" id="filename" placeholder="" type="file" >
                        <input name="fileId" id="fileId" style="display: none" value="${fileId}">
                    </div>
                </div>


            </form>
            <!--===================================================-->
            <!-- END BASIC FORM ELEMENTS -->

            <div class="panel-footer">
                <a class="btn btn-default" id="apply-re-common" href="javascript:void(0)">
                    <i class="fa fa-lg fa-mail-reply"></i> 返回
                </a>
                <a class="btn btn-success" id="btn-save-common" href="javascript:void(0);"><i class="fa fa-lg fa-download"></i> 保存 </a>
                <c:if test="${dispatch==null || dispatch.processState=='Draft'}">
                    <a class="btn btn-warning" id="btn-commit-common" href="javascript:void(0);"><i class="fa fa-upload"></i> 提交 </a>
                </c:if>
                <c:if test="${dispatch!=null && dispatch.processState=='Backed'}">
                    <a class="btn btn-warning" id="btn-recommit-common" href="javascript:void(0);"><i class="fa fa-upload"></i> 再提交 </a>
                </c:if>
            </div>
        </div>

<script>
    var index = "${index}";
    var todo = "${todo}";
    var remind = "${remind}";
    var record = "${record}";
    var draft =  "${draft}";

    $(function(){
        var pdata= {
            keyId:$("#keyId").val(),
            entityName:"com.fz.us.oa.core.entity.com.Dispatch"
        };
        multiDuty(pdata);
        fn_dispatch_input_validate()
    });

    // 日期选择
    $('#validDate').datepicker({
        format: 'yyyy-mm-dd',
        weekStart: 1,
        autoclose: true,
        todayBtn: 'linked',
        todayHighlight: true,
        language: 'zh-CN'
    });

    // 日期选择
    $('#time').datepicker({
        format: 'yyyy-mm-dd',
        weekStart: 1,
        autoclose: true,
        todayBtn: 'linked',
        todayHighlight: true,
        language: 'zh-CN'
    });
    // 时间选择
    $('.clockpicker').clockpicker({
        autoclose: true,
        default: 'now'
    });
    // 附件上传
    inputLoad({
        objId:"filename",
        entityName:"fileIds",
        sourceId:"fileId",
        jsessionid:"<%=jsessionid%>"
    });

    // 字典列表下拉框
    $("#typedictId").select2({
        placeholder: "请选择一个发文类别",
        allowClear: true
    });
    $(':radio[name="object"]').click(function(){
        if($(this).val()=="1") {
            $('#showPerson').hide();
            $('#showDept').hide();
        }else if($(this).val()=="2"){
            $('#showPerson').hide();
            $('#showDept').show();
        }else if($(this).val()=="3"){
            $('#showPerson').show();
            $('#showDept').hide();
        }
    });

    $(':radio[name="hasValid"]').click(function(){
        if($(this).val()=="1") {
            $('#showValid').show();
        }else{
            $('#showValid').hide();
        }
    });

    // 表单数据校验
    function fn_dispatch_input_validate() {
        __init_validate('form_dispatch_input', {
            rules : {
                typedictId : {
                    required : true
                },
                title : {
                    required : true
                },
                fileNo : {
                    required : true
                },
                time : {
                    required : true
                },
                object:{
                    required : true
                },
                hasValid: {
                    required : true
                },
                validDate:{
                    required : function(){
                        if($(':checked[name="hasValid"]').val() == "1"){
                            return true;
                        }else{
                            return false;
                        }
                    }
                },
                noticeDepartmentId:{
                    required:function(){
                        if($(':checked[name="object"]').val() == "2"){
                            return true;
                        }else{
                            return false;
                        }
                    }
                },
                noticeUsersId:{
                    required:function(){
                        if($(':checked[name="object"]').val() == "3"){
                            return true;
                        }else{
                            return false;
                        }
                    }
                },
                fileIds:{
                    required:true
                }
            },
            messages : {
                typedictId : {
                    required : "请选择发文类别"
                },
                title : {
                    required : "请输入发文标题"
                },
                fileNo : {
                    required : "请输入文件编号"
                },
                time : {
                    required : "请选择发文时间"
                },
                object : {
                    required : "请选择发文对象"
                },
                hasValid : {
                    required : "请选择是否具有有效期"
                },
                validDate: {
                    required : "请选择有效期"
                },
                noticeDepartmentId:{
                    required: "请选择通知部门"
                },
                noticeUsersId:{
                    required: "请选择通知个人"
                },
                fileIds:{
                    required:"请选择相关附件"
                }
            }
        });
    }
    //保存
    $("#btn-save-common").click(
            function(e) {
                __confirm_dialog("提示：","确定保存吗？",
                        function () {
                            __form_save("form_dispatch_input", "<%=path%>/com/dispatch/save",function(){
                                $("#apply-re-common").trigger("click");
                            })
                        }
                )
            }
    );

    //提交
    $("#btn-commit-common,#btn-recommit-common").click(
            function(e) {
                if (!$('#form_dispatch_input').valid()) {
                    return false;
                }

                __confirm_dialog("提示：","确定提交么?",
                        function () {
                            __form_save("form_dispatch_input", "<%=path%>/com/dispatch/commit",function(){
                                $("#apply-re-common").trigger("click");
                            })
                        }
                )
            }
    );


    //返回视图
    $("#apply-re-common").click(function(){

        if(index==1){
            loadURL("menu/dashboard",$('#page-content'));
        }else if(todo==1){
            loadURL("menu/toDo",$('#page-content'));
        }else if(remind==1){
            loadURL("menu/remind",$('#page-content'));
        }else if(record==1){
            loadURL("menu/taskRecord?type=1",$('#page-content'));
        }else if(record==2){
            loadURL("menu/taskRecord?type=2",$('#page-content'));
        }else if(draft==1){
            loadURL("menu/draft",$('#page-content'));
        }else{
            returnToHashUrl()
        }
    });




</script>




